/**
 *
 */
package soa.security.rs.impl;

import org.springframework.ldap.NamingException;
import org.springframework.stereotype.Service;
import soa.security.domain.Department;
import soa.security.exception.OrganizationException;
import soa.security.mgr.service.*;
import soa.security.rs.DepartmentService;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Cre.Gu
 */
@Service
public class DepartmentRsServiceImpl implements DepartmentService {
    protected final org.slf4j.Logger log = org.slf4j.LoggerFactory
            .getLogger(this.getClass());

    @Resource
    private DepartmentMgrService departmentMgrService;
    @Resource
    private PersonMgrService personMgrService;
    @Resource
    private PositionMgrService positionMgrService;
    @Resource
    private GroupMgrService groupMgrService;
    @Resource
    private RoleMgrService roleMgrService;


    @Override
    public Department getDepartment(String organizationId, String departmentId)
            throws OrganizationException {
        try {
            List<Department> list = departmentMgrService.getDepartment(
                    organizationId, departmentId);

            if (list != null && list.size() > 0)
                return list.get(0);

            return null;
        } catch (NamingException e) {
            throw new OrganizationException(OrganizationException.ERROR_LDAP, e);
        } catch (OrganizationException e) {
            throw e;
        } catch (Exception e) {
            if (log.isDebugEnabled())
                log.debug("其他错误", e);
            throw new OrganizationException(OrganizationException.ERROR_OTHER, e);
        }
    }
}
